package com.ewhale.feitengguest.presenter.shop.deal

import com.ewhale.feitengguest.api.ApiHelper
import com.ewhale.feitengguest.dto.SubmitDetailDto
import com.ewhale.feitengguest.view.shop.deal.HandlerTaskView
import com.simga.library.base.IPresenter
import com.simga.library.http.APIException
import com.simga.library.http.JsonUtil
import com.simga.library.utils.LogUtil
import java.util.logging.Logger

class HandlerTaskPresenter : IPresenter() {
    fun loadSubmitDetail(taskId: Long) {
        mView.showProLoading()
        request(1, ApiHelper.TASK_API.getSubmitDetail(taskId), null)
    }
    override fun <T : Any?> onNext(postCode: Int, result: T, data: Any?) {
        super.onNext(postCode, result, data)
        when (postCode) {
            1 -> (mView as HandlerTaskView).showSubmitDetails(result as SubmitDetailDto)
            2 -> (mView as HandlerTaskView).updateTaskDetail(data as Int)
        }
    }

    override fun otherException(postCode: Int, data: Any?, e: APIException?) {
        super.otherException(postCode, data, e)
        mView.showErrorMessage(postCode, e!!.code, e.displayMessage)
    }

    fun agreeOrUnAgree(Id: Int, status: Int, refuseReason: String) {
        mView.showProLoading()
        val params = HashMap<String,Any>()
        params["Id"] = Id
        params["status"] = status
        if(status == 2){
            params["refuseReason"] = refuseReason
        }
        LogUtil.e("JIA","---params : " + JsonUtil.toJson(params))
        request(2, ApiHelper.TASK_API.updateAccountMissionStatus(params), status)
    }
}
